Function.prototype.myCall = function (context = window, ...args) {
    const fn = Symbol("fn");
    context[fn] = this;
    context[fn](...args);
    delete context[fn];
};

Function.prototype.myApply = function (context = window, args) {
    const fn = Symbol("fn");
    context[fn] = this;
    context[fn](...args);
    delete context[fn];
};

Function.prototype.myBind = function (context = window, ...args) {
    let func = this;
    let fbound = function () {
        console.log("this", this);
        func.apply(this instanceof func ? this : context, [
            ...args,
            ...arguments,
        ]);
    };
    fbound.prototype = Object.create(func.prototype);
    return fbound;
};

function foo(...args) {
    console.log([...args]);
}

const obj = { name: "kaho" };

let func = foo.myBind(obj, 1, 2, 3);

const fobj = new func();

console.log(fobj);
